//
//  PointerArray.h
//  GLDemo
//
//  Created by wenqi on 5/23/14.
//  Copyright (c) 2014 xiewneqi. All rights reserved.
//

#ifndef __GLDemo__PointerArray__
#define __GLDemo__PointerArray__

#include <iostream>

template<typename ArrayType>
class PointerArray
{
public:
    PointerArray () : m_buffer (NULL)
    {
        // do nothing
    }
    
    PointerArray (unsigned int elementCount)
    {
        m_buffer = new ArrayType [elementCount];
        std::cout << m_buffer << std::endl;
    }
    
    PointerArray (const PointerArray& pointerArray) : m_buffer (pointerArray.m_buffer)
    {
        // do nothing
    }
    
    ~PointerArray ()
    {
        if (m_buffer != NULL)
        {
            delete[] m_buffer;
            m_buffer = NULL;
        }
    }
    
public:
    ArrayType* Malloc (unsigned int elementCount)
    {
        if (m_buffer != NULL)
        {
            throw "Malloc操作之前请确保缓冲区没有被占用";
        }
        m_buffer = new ArrayType[elementCount];
        return m_buffer;

    }
    
    void Free ()
    {
        if (m_buffer == NULL)
        {
            return;
        }
        delete[] m_buffer;
        m_buffer = NULL;

    }
    
    ArrayType* &GetBuffer ()
    {
        return m_buffer;
    }
    
    
    
private:
    ArrayType* m_buffer;
};

#endif /* defined(__GLDemo__PointerArray__) */
